package sq.sms;

import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author BianYang
 */
public class SqSmsSender implements TplSmsSender {
    @Autowired
    IAcsClient iAcsClient;

    SqSmsSender(IAcsClient iAcsClient) {
        this.iAcsClient = iAcsClient;
    }

    @Override
    public SendSmsResponse send(String phone, String tplId, String params) throws ClientException {
        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
        System.setProperty("sun.net.client.defaultReadTimeout", "10000");
        SendSmsResponse sendSmsResponse;
        //组装请求对象-具体描述见控制台-文档部分内容
        SendSmsRequest request = new SendSmsRequest();
        //必填:待发送手机号
        request.setPhoneNumbers(phone);
        //必填:短信签名-可在短信控制台中找到
        request.setSignName("sq短信");
        //必填:短信模板-可在短信控制台中找到
        request.setTemplateCode(tplId);
        request.setTemplateParam(params);
        sendSmsResponse = iAcsClient.getAcsResponse(request);
        return sendSmsResponse;
    }

}
